package com.acme.bankapp.domain.bank;

/**
 * Abstract class provides account functionality
 * @author alex
 */
@SuppressWarnings("serial")
public abstract class AbstractAccount implements Account, Cloneable {
	protected int accountId;
	protected double balance;
	
	protected static int lastAccountId;
	
	/**
	 * The default constructor
	 */
	public AbstractAccount() {
		this.accountId = AbstractAccount.lastAccountId++;
	}
	
	/**
	 * @return the account id
	 */
	public int getAccountId() {
		return this.accountId;
	}
	
	/**
	 * @return the balance
	 */
	public double getBalance() {
		return this.balance;
	}
	
	/**
	 * @param x the money
	 */
	public void deposit(double x) {
		this.balance += x;
	}
	
	/**
	 * @return the decimal value of balance
	 */
	public long decimalValue() {
		return Math.round(this.balance);
	}
	
	/**
	 * @param account the account
	 */
	@Override
	public int compareTo(Account account) {
		if (this.balance < account.getBalance())
			return -1;
		else if (this.balance == account.getBalance())
			return 0;
		else
			return 1;
	}
	
	/**
	 * @return the account copy
	 */
	@Override
	protected Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
}
